#!/usr/bin/env bash
# 安装 docker 相关
## 1. 卸载 docker
echo '>>>>>>>>>>>>>>>>>>>> [docker] 1. remove docker'
sudo yum remove docker \
    docker-client \
    docker-client-latest \
    docker-common \
    docker-latest \
    docker-latest-logrotate \
    docker-logrotate \
    docker-engine
## 2. 安装 docker 依赖
echo '>>>>>>>>>>>>>>>>>>>> [docker] 2. install dependencies'
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
## 3. 备份原文件
echo '>>>>>>>>>>>>>>>>>>>> [docker] backup file'
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
## 4. 修改yum源
echo '>>>>>>>>>>>>>>>>>>>> [docker] update yum'
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
## 5. 安装 docker-ce
echo '>>>>>>>>>>>>>>> [docker] install docker'
sudo yum install -y docker-ce docker-ce-cli containerd.io
## 6. docker加速
echo '>>>>>>>>>>>>>>>>>>>> [docker] docker daemon.json '
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
 # 高版本k8s，需要此配置
 "exec-opts": ["native.cgroupdriver=systemd"],
 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
EOF
sudo systemctl daemon-reload

## 7. 启动docker
echo '>>>>>>>>>>>>>>>>>>>> [docker] start'
systemctl restart docker
systemctl enable docker

docker -v